package com.example.drawex;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class BitmapScaleView extends View {
	
	// 확대, 축소 비율
	float scale=1.0f;
	
	
	
	public void setScale(float f) {
		this.scale = f;
		invalidate();
	}
	

	public BitmapScaleView(Context context, AttributeSet attr) {
		super(context, attr);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {

		// 원본 이미지
		Paint paint = new Paint();
		Bitmap ori = BitmapFactory.decodeResource(getResources(), R.drawable.bang2011);
		
		canvas.drawBitmap(ori, 10, 10, null);
		
		
		// 확대/축소된 이미지
		int w = (int)Math.ceil(ori.getWidth() * scale);
		int h = (int)Math.ceil(ori.getHeight() * scale);
		
		Bitmap scaleBitmap = Bitmap.createScaledBitmap(ori, w, h, false);
		canvas.drawBitmap(scaleBitmap, 10, 10, null);
		
		super.onDraw(canvas);
	}
	
}
